package com.doit.demo04;

import java.io.FileNotFoundException;

/*
*   定义一个方法 获取一个 整数数组中最后一位元素
*   并在main方法中调用 并打印这个元素值
* */
public class test01 {
    public static void main(String[] args) {
        int [] a = {0,2,0,5};

        try{
            int b  = method(a);
            System.out.println(b);
        }catch (Exception e){
            System.out.println(e);
        }finally {
            System.out.println("老子必须执行");
        }

        System.out.println("-------------------");
//        int s =
                m();
//        System.out.println(s);

        System.out.println("============");
        try {
            mm(2);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

    public static void mm(int a) throws FileNotFoundException, ClassNotFoundException {
        if(a==2)
            throw new FileNotFoundException("没有文件");
        if(a==3)
            throw new ClassNotFoundException("类超限了");
        System.out.println("代码正常执行");
    }

    private static int m() {

        int i = 10;
        try{
            i=1/0;
        }catch(Exception e)
        {
            i=1651;

//            try{i=1/0;}
//            catch(Exception ee){i=1059;}
//                finally {

        }
         finally {
//            i=20;
            return i;
        }
    }


    private static int method(int[] a) {

        return a[a.length-1];
    }
    private static int method(int [] a , int b)
    {
        return a[b];
    }
}
